/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package GUI;

import BUS.HoaDonBUS;
import BUS.TinhTrangGheBUS;
import BUS.VeBUS;
import BUS.XuLyLinhTinhBUS;
import DAO.ExcuteQuery;
import DAO.TaoMaHoaDon;
import DAO.TuyenTauDAO;
import DTO.ChuyenTauDTO;
import DTO.DoiTuongDTO;
import DTO.GaDTO;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import javax.swing.DefaultComboBoxModel;
import DTO.KhachHang;
import DTO.ToaDTO;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JOptionPane;
import DTO.Ghe;
import DTO.HoaDonDTO;
import DTO.NguoiDung;
import DTO.UserList;
import DTO.VeDTO;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Locale;
import java.util.Vector;
import javax.swing.table.DefaultTableModel;

/**
 *
 * @author Nobita Chau
 */
public class BanVeGUI extends javax.swing.JPanel {

    /**
     * Creates new form BanVeGUI
     */
     public UserList us = new UserList();
      String TenGroup;
     public String tendangnhap;
    public BanVeGUI(String tendn) {
             initComponents();
        tendangnhap=tendn;
   
        LoadForm();
    }
    // Chưa lấy được tên đăng nhập truyền vào 
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd", Locale.getDefault());

     DefaultComboBoxModel<String> a= new DefaultComboBoxModel<String>();
    DefaultComboBoxModel<String> b = new DefaultComboBoxModel<String>();
    DefaultComboBoxModel<String> d = new DefaultComboBoxModel<String>();
    public ResultSet rs;
    public void LoadForm(){
        try {
            // Load tên và loại nhân viên
            String sql =" select nd.HO_TEN , lnv.TEN  from USERLIST ul, NGUOI_DUNG nd, NHAN_VIEN nv, LOAI_NHAN_VIEN lnv where ul.ID_ND = nd.ID and ul.USERNAME='"+ tendangnhap+"' and nd.ID=nv.NGUOI_DUNG and nv.LOAI_NV=lnv.ID ";
             rs = ExcuteQuery.TimKiemTatCa(sql);
            String name;
            String loai;
            while (rs.next()) {
                 name = rs.getString("Ho_ten");
                 loai = rs.getString("Ten");
                  this.jLabelTenNV.setText(name);
                  this.jLabelLoaiNV.setText(loai);
            }
           
            // Load tên khách hàng và thông tin của khách hàng
            String sql1 = "select  nd.HO_TEN  from NGUOI_DUNG nd where nd.LOAI_NGUOI_DUNG=1";
             rs = ExcuteQuery.TimKiemTatCa(sql1);
            ArrayList<KhachHang> dskh = new ArrayList<KhachHang>();
            while (rs.next()) {
               KhachHang temp = new KhachHang();
               temp.HoTen= rs.getString("HO_TEN");
               dskh.add(temp);
            }
             for (KhachHang k : dskh) {
                a.addElement(k.HoTen);
            }
            jcbTenKH.setModel(a);
            
   
            // Ga đi ga đến
            String sql2 = "Select n.ID, n.Ten from Ga n";
             rs = ExcuteQuery.TimKiemTatCa(sql2);
            ArrayList<GaDTO> dsga = new ArrayList<GaDTO>();
            while (rs.next()) {
                GaDTO temp = new GaDTO();
                temp.id = rs.getInt("ID");
                temp.tenga = rs.getString("Ten");
                dsga.add(temp);
            }
            for (GaDTO k : dsga) {
                b.addElement(k.tenga);
                d.addElement(k.tenga);
            }
            jcbGaDen.setModel(b);
            jcbGaDi.setModel(d);
            
            String maHD = TaoMaHoaDon.LayMaHoaDonTenUser("call laymahoadon(?)", "HD",tendangnhap);
            jtfHoaDon.setText(maHD);
            
        } catch (SQLException ex) {
           System.err.println(ex);
        }
    }
    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jPanel2 = new javax.swing.JPanel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jcbTenKH = new javax.swing.JComboBox();
        jtfSoCMNDKH = new javax.swing.JTextField();
        jLabel15 = new javax.swing.JLabel();
        jtfGioiTinh = new javax.swing.JTextField();
        jLabel16 = new javax.swing.JLabel();
        jtfSDT = new javax.swing.JTextField();
        jPanel3 = new javax.swing.JPanel();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        jLabelTenNV = new javax.swing.JLabel();
        jLabelLoaiNV = new javax.swing.JLabel();
        jPanel4 = new javax.swing.JPanel();
        jLabel6 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        jcbGaDi = new javax.swing.JComboBox();
        jcbGaDen = new javax.swing.JComboBox();
        jLabel8 = new javax.swing.JLabel();
        jbTim = new javax.swing.JButton();
        jDateNgayDi = new com.toedter.calendar.JDateChooser();
        jPanel5 = new javax.swing.JPanel();
        jLabel9 = new javax.swing.JLabel();
        jLabel10 = new javax.swing.JLabel();
        jcbChuyen = new javax.swing.JComboBox();
        jcbToa = new javax.swing.JComboBox();
        jLabel11 = new javax.swing.JLabel();
        jbTim1 = new javax.swing.JButton();
        jcbGheGiuong = new javax.swing.JComboBox();
        jcbDoiTuong = new javax.swing.JComboBox();
        jLabel12 = new javax.swing.JLabel();
        jLabel13 = new javax.swing.JLabel();
        jtfHoaDon = new javax.swing.JTextField();
        jLabel14 = new javax.swing.JLabel();
        jlbGiaVe = new javax.swing.JLabel();
        jbTim2 = new javax.swing.JButton();
        jLabel17 = new javax.swing.JLabel();
        jtfTau = new javax.swing.JTextField();
        jtfGiaGhe = new javax.swing.JTextField();
        jtfTinhTrang = new javax.swing.JTextField();
        jtfLoaiGhe = new javax.swing.JTextField();
        jLabel18 = new javax.swing.JLabel();
        jLabel19 = new javax.swing.JLabel();
        jLabel20 = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        jtbBanVe = new javax.swing.JTable();

        jPanel1.setBackground(new java.awt.Color(0, 0, 255));

        jLabel1.setFont(new java.awt.Font("Tahoma", 1, 24)); // NOI18N
        jLabel1.setForeground(new java.awt.Color(255, 255, 255));
        jLabel1.setText("BÁN VÉ");

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(444, 444, 444)
                .addComponent(jLabel1)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                .addGap(0, 0, Short.MAX_VALUE)
                .addComponent(jLabel1))
        );

        jPanel2.setBackground(new java.awt.Color(204, 255, 255));

        jLabel2.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        jLabel2.setForeground(new java.awt.Color(255, 0, 0));
        jLabel2.setText("Tên Khách Hàng:");

        jLabel3.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        jLabel3.setForeground(new java.awt.Color(255, 0, 0));
        jLabel3.setText("Số CMND:");

        jcbTenKH.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
        jcbTenKH.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jcbTenKHActionPerformed(evt);
            }
        });

        jtfSoCMNDKH.setEnabled(false);

        jLabel15.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        jLabel15.setForeground(new java.awt.Color(255, 0, 0));
        jLabel15.setText("Giới Tính:");

        jtfGioiTinh.setEnabled(false);

        jLabel16.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        jLabel16.setForeground(new java.awt.Color(255, 0, 0));
        jLabel16.setText("Điện Thoại:");

        jtfSDT.setEnabled(false);

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel2)
                    .addComponent(jLabel3))
                .addGap(27, 27, 27)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jcbTenKH, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jtfSoCMNDKH, javax.swing.GroupLayout.DEFAULT_SIZE, 185, Short.MAX_VALUE))
                .addGap(36, 36, 36)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel15)
                    .addComponent(jLabel16))
                .addGap(31, 31, 31)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jtfSDT, javax.swing.GroupLayout.PREFERRED_SIZE, 166, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jtfGioiTinh, javax.swing.GroupLayout.PREFERRED_SIZE, 166, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabel15)
                        .addComponent(jtfGioiTinh, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabel2)
                        .addComponent(jcbTenKH, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addGap(26, 26, 26)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabel16)
                        .addComponent(jtfSDT, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabel3)
                        .addComponent(jtfSoCMNDKH, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jPanel3.setBackground(new java.awt.Color(204, 255, 255));

        jLabel4.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        jLabel4.setForeground(new java.awt.Color(255, 0, 0));
        jLabel4.setText("Tên Nhân Viên:");

        jLabel5.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        jLabel5.setForeground(new java.awt.Color(255, 0, 0));
        jLabel5.setText("Loại Nhân Viên:");

        jLabelTenNV.setFont(new java.awt.Font("Arial", 1, 11)); // NOI18N
        jLabelTenNV.setText("....");

        jLabelLoaiNV.setFont(new java.awt.Font("Arial", 1, 11)); // NOI18N
        jLabelLoaiNV.setText("....");

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel4)
                    .addComponent(jLabel5))
                .addGap(26, 26, 26)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabelLoaiNV)
                    .addComponent(jLabelTenNV))
                .addContainerGap(103, Short.MAX_VALUE))
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel4)
                    .addComponent(jLabelTenNV))
                .addGap(31, 31, 31)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel5)
                    .addComponent(jLabelLoaiNV))
                .addContainerGap(19, Short.MAX_VALUE))
        );

        jPanel4.setBackground(new java.awt.Color(204, 255, 255));

        jLabel6.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        jLabel6.setForeground(new java.awt.Color(255, 0, 0));
        jLabel6.setText("Ga Đi");

        jLabel7.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        jLabel7.setForeground(new java.awt.Color(255, 0, 0));
        jLabel7.setText("Ga Đến");

        jcbGaDi.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));

        jcbGaDen.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));

        jLabel8.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        jLabel8.setForeground(new java.awt.Color(255, 0, 0));
        jLabel8.setText("Ngày đi:");

        jbTim.setFont(new java.awt.Font("Arial", 1, 12)); // NOI18N
        jbTim.setText("1. Tìm");
        jbTim.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbTimActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
        jPanel4.setLayout(jPanel4Layout);
        jPanel4Layout.setHorizontalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel6)
                .addGap(18, 18, 18)
                .addComponent(jcbGaDi, javax.swing.GroupLayout.PREFERRED_SIZE, 185, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(jLabel7)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jcbGaDen, javax.swing.GroupLayout.PREFERRED_SIZE, 185, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(28, 28, 28)
                .addComponent(jLabel8)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jDateNgayDi, javax.swing.GroupLayout.PREFERRED_SIZE, 170, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jbTim)
                .addGap(53, 53, 53))
        );
        jPanel4Layout.setVerticalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabel6)
                        .addComponent(jcbGaDi, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jLabel8)
                        .addComponent(jcbGaDen, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jLabel7)
                        .addComponent(jbTim))
                    .addComponent(jDateNgayDi, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jPanel5.setBackground(new java.awt.Color(204, 255, 255));

        jLabel9.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        jLabel9.setForeground(new java.awt.Color(255, 0, 0));
        jLabel9.setText("Chuyến");

        jLabel10.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        jLabel10.setForeground(new java.awt.Color(255, 0, 0));
        jLabel10.setText("Toa");

        jcbChuyen.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
        jcbChuyen.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jcbChuyenActionPerformed(evt);
            }
        });

        jcbToa.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
        jcbToa.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jcbToaActionPerformed(evt);
            }
        });

        jLabel11.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        jLabel11.setForeground(new java.awt.Color(255, 0, 0));
        jLabel11.setText("Ghế/ Giường:");

        jbTim1.setFont(new java.awt.Font("Arial", 1, 12)); // NOI18N
        jbTim1.setText("2. Bán vé");
        jbTim1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbTim1ActionPerformed(evt);
            }
        });

        jcbGheGiuong.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
        jcbGheGiuong.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jcbGheGiuongActionPerformed(evt);
            }
        });

        jcbDoiTuong.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
        jcbDoiTuong.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jcbDoiTuongActionPerformed(evt);
            }
        });

        jLabel12.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        jLabel12.setForeground(new java.awt.Color(255, 0, 0));
        jLabel12.setText("Đối tượng:");

        jLabel13.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        jLabel13.setForeground(new java.awt.Color(255, 0, 0));
        jLabel13.setText("Hóa Đơn:");

        jtfHoaDon.setEnabled(false);

        jLabel14.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        jLabel14.setForeground(new java.awt.Color(255, 0, 0));
        jLabel14.setText("Giá Vé:");

        jlbGiaVe.setFont(new java.awt.Font("Arial", 1, 11)); // NOI18N
        jlbGiaVe.setText(".....");

        jbTim2.setFont(new java.awt.Font("Arial", 1, 12)); // NOI18N
        jbTim2.setText("3. Thanh Toán");
        jbTim2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbTim2ActionPerformed(evt);
            }
        });

        jLabel17.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        jLabel17.setForeground(new java.awt.Color(255, 0, 0));
        jLabel17.setText("Tàu:");

        jtfTau.setEnabled(false);

        jtfGiaGhe.setEnabled(false);

        jtfTinhTrang.setEnabled(false);

        jtfLoaiGhe.setEnabled(false);

        jLabel18.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        jLabel18.setForeground(new java.awt.Color(255, 0, 0));
        jLabel18.setText("Loại Ghế:");

        jLabel19.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        jLabel19.setForeground(new java.awt.Color(255, 0, 0));
        jLabel19.setText("Giá:");

        jLabel20.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        jLabel20.setForeground(new java.awt.Color(255, 0, 0));
        jLabel20.setText("Tình Trạng:");

        javax.swing.GroupLayout jPanel5Layout = new javax.swing.GroupLayout(jPanel5);
        jPanel5.setLayout(jPanel5Layout);
        jPanel5Layout.setHorizontalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel5Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(jPanel5Layout.createSequentialGroup()
                        .addComponent(jLabel11)
                        .addGap(18, 18, 18)
                        .addComponent(jcbGheGiuong, javax.swing.GroupLayout.PREFERRED_SIZE, 185, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel5Layout.createSequentialGroup()
                        .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jLabel10)
                            .addComponent(jLabel9))
                        .addGap(33, 33, 33)
                        .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jcbToa, javax.swing.GroupLayout.PREFERRED_SIZE, 185, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jcbChuyen, javax.swing.GroupLayout.PREFERRED_SIZE, 185, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addGap(38, 38, 38)
                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel5Layout.createSequentialGroup()
                        .addComponent(jLabel17)
                        .addGap(74, 74, 74)
                        .addComponent(jtfTau, javax.swing.GroupLayout.PREFERRED_SIZE, 150, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel5Layout.createSequentialGroup()
                        .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel18)
                            .addComponent(jLabel19))
                        .addGap(44, 44, 44)
                        .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jtfLoaiGhe, javax.swing.GroupLayout.PREFERRED_SIZE, 149, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGroup(jPanel5Layout.createSequentialGroup()
                                .addComponent(jtfGiaGhe, javax.swing.GroupLayout.PREFERRED_SIZE, 111, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(18, 18, 18)
                                .addComponent(jLabel20))
                            .addComponent(jtfHoaDon, javax.swing.GroupLayout.PREFERRED_SIZE, 150, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addComponent(jLabel13))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel5Layout.createSequentialGroup()
                        .addComponent(jLabel14)
                        .addGap(47, 47, 47)
                        .addComponent(jlbGiaVe)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jbTim1)
                            .addComponent(jbTim2)))
                    .addGroup(jPanel5Layout.createSequentialGroup()
                        .addComponent(jtfTinhTrang, javax.swing.GroupLayout.PREFERRED_SIZE, 116, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(jLabel12)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jcbDoiTuong, javax.swing.GroupLayout.PREFERRED_SIZE, 159, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(0, 120, Short.MAX_VALUE))))
        );
        jPanel5Layout.setVerticalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel5Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel9)
                    .addComponent(jcbChuyen, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel17)
                    .addComponent(jtfTau, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jcbToa, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel10)
                    .addComponent(jtfLoaiGhe, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel18))
                .addGap(2, 2, 2)
                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(jPanel5Layout.createSequentialGroup()
                        .addGap(9, 9, 9)
                        .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jtfGiaGhe, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel20)
                            .addComponent(jtfTinhTrang, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel12)
                            .addComponent(jcbDoiTuong, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jbTim1)
                        .addGap(11, 11, 11)
                        .addComponent(jbTim2)
                        .addGap(0, 0, Short.MAX_VALUE))
                    .addGroup(jPanel5Layout.createSequentialGroup()
                        .addGap(12, 12, 12)
                        .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel19)
                            .addComponent(jcbGheGiuong, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel11))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 25, Short.MAX_VALUE)
                        .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel13)
                            .addComponent(jtfHoaDon, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel14)
                            .addComponent(jlbGiaVe))
                        .addGap(39, 39, 39))))
        );

        jtbBanVe.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {},
                {},
                {},
                {}
            },
            new String [] {

            }
        ));
        jScrollPane1.setViewportView(jtbBanVe);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                    .addComponent(jPanel4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jPanel5, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jScrollPane1))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(9, 9, 9)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 166, Short.MAX_VALUE)
                .addContainerGap())
        );
    }// </editor-fold>//GEN-END:initComponents

    private void jcbTenKHActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jcbTenKHActionPerformed
        try {
            // TODO add your handling code here:
            String tenkh = jcbTenKH.getSelectedItem().toString();
            String sql5 = "select nd.gioi_tinh,nd.SO_CMND,nd.DIEN_THOAI from NGUOI_DUNG nd where nd.LOAI_NGUOI_DUNG=1 and nd.HO_TEN ='"+tenkh+"'";
             rs = ExcuteQuery.TimKiemTatCa(sql5);
            ArrayList<KhachHang> dskh = new ArrayList<KhachHang>();
            while (rs.next()) {
               KhachHang temp = new KhachHang();
                temp.GioiTinh = rs.getString("Gioi_Tinh");
                temp.So_CMND = rs.getString("SO_CMND");
                temp.DienThoai= rs.getString("DIEN_THOAI");  
                dskh.add(temp);
              for (KhachHang k : dskh) {
               jtfGioiTinh.setText(k.GioiTinh);
               jtfSDT.setText(k.DienThoai);
               jtfSoCMNDKH.setText(k.So_CMND);
            }
               
               
            }
        } catch (SQLException ex) {
           System.err.println(ex);
        }
            
    }//GEN-LAST:event_jcbTenKHActionPerformed
DefaultComboBoxModel<String> c = new DefaultComboBoxModel<String>();
DefaultComboBoxModel<String> e = new DefaultComboBoxModel<String>();
DefaultComboBoxModel<String> f = new DefaultComboBoxModel<String>();
    private void jbTimActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbTimActionPerformed
        try {
            // TODO add your handling code here:
            if ( jcbGaDi.getSelectedItem() == jcbGaDen.getSelectedItem()){
                JOptionPane.showMessageDialog(null, "Ga Đi Và Ga Đến Trùng Nhau ! Xin Chọn Lại","Thông Báo" , JOptionPane.INFORMATION_MESSAGE);
                return;
            }
            
            int gadi =0;
            int gaden =0;
            
            
                
                String sql2 = "Select n.ID, n.Ten from Ga n";
                ResultSet rs = ExcuteQuery.TimKiemTatCa(sql2);
                ArrayList<GaDTO> dsga = new ArrayList<GaDTO>();
                while (rs.next()) {
                    GaDTO temp = new GaDTO();
                    temp.id = rs.getInt("ID");
                    temp.tenga = rs.getString("Ten");
                    dsga.add(temp);
                }
                for (GaDTO k : dsga) {
                    if( jcbGaDen.getSelectedItem().equals( k.tenga) ){
                        gaden = k.id;
                    }
                    if( jcbGaDi.getSelectedItem().equals( k.tenga) ){
                        gadi = k.id;
                    }
                }
                
            String tuyen = TuyenTauDAO.timTuyen(gadi, gaden);
            if (TuyenTauDAO.timTuyenTauCanDi(tuyen, sdf.format(jDateNgayDi.getDate()).toString()).next() == false){
                  JOptionPane.showMessageDialog(null, "Không Có Ga Phù Hợp", "Thông Báo", JOptionPane.INFORMATION_MESSAGE);
                  return;
            }
            
             JOptionPane.showMessageDialog(null, "Đã tìm thấy tuyến có phù hợp", "Thông Báo", JOptionPane.INFORMATION_MESSAGE);
            // Lấy lên jcombo Chuyến
             
            rs = TuyenTauDAO.timTuyenTauCanDi(tuyen,  sdf.format(jDateNgayDi.getDate()).toString());
            ArrayList<ChuyenTauDTO> dsct = new ArrayList<ChuyenTauDTO>();
          
            while (rs.next()) {
               ChuyenTauDTO temp = new ChuyenTauDTO();
               temp.id= rs.getString("Id");
             
               dsct.add(temp);
               
            }
             for (ChuyenTauDTO k : dsct) {
                c.addElement(k.id);
            }
            jcbChuyen.setModel(c);
            
            // Lấy lên jcombo Đối Tượng
       
                String sql9 = "Select n.ID, n.Ten from doi_tuong n";
                rs = ExcuteQuery.TimKiemTatCa(sql9);
                ArrayList<DoiTuongDTO> dsdt = new ArrayList<DoiTuongDTO>();
                while (rs.next()) {
                    DoiTuongDTO temp = new DoiTuongDTO();
                    temp.id = rs.getInt("ID");
                    temp.Ten = rs.getString("Ten");
                    dsdt.add(temp);
                }
                for (DoiTuongDTO k : dsdt) {
                    e.addElement(k.Ten);
                }
                jcbDoiTuong.setModel(e);
            
        } catch (Exception ex) {
                JOptionPane.showMessageDialog(null, ex.getStackTrace(), "Thông báo lỗi", JOptionPane.OK_OPTION);
                
            }
    }//GEN-LAST:event_jbTimActionPerformed

    private void jcbChuyenActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jcbChuyenActionPerformed
        try {
            // TODO add your handling code here:
            int gadi =0;
            int gaden =0;
            
            
            
            String sql2 = "Select n.ID, n.Ten from Ga n";
            ResultSet rs = ExcuteQuery.TimKiemTatCa(sql2);
            ArrayList<GaDTO> dsga = new ArrayList<GaDTO>();
            while (rs.next()) {
                GaDTO temp = new GaDTO();
                temp.id = rs.getInt("ID");
                temp.tenga = rs.getString("Ten");
                dsga.add(temp);
            }
            for (GaDTO k : dsga) {
                if( jcbGaDen.getSelectedItem().equals( k.tenga) ){
                    gaden = k.id;
                }
                if( jcbGaDi.getSelectedItem().equals( k.tenga) ){
                    gadi = k.id;
                }
            }
            String tuyen = TuyenTauDAO.timTuyen(gadi, gaden);
            rs = TuyenTauDAO.timTuyenTauCanDi(tuyen, sdf.format(jDateNgayDi.getDate()).toString());
            ArrayList<ChuyenTauDTO> dsct = new ArrayList<ChuyenTauDTO>();
            String tentau ;
            while (rs.next()) {
                ChuyenTauDTO temp = new ChuyenTauDTO();
                temp.id= rs.getString("Id");
                temp.Tau = rs.getString("IDTAU");
                dsct.add(temp);
                
            }
            for (ChuyenTauDTO k : dsct) {
                if( jcbChuyen.getSelectedItem().equals( k.id) ){
                    tentau = k.Tau;
                    this.jtfTau.setText(tentau);
                }
            }
            
              String sql = String.format("select  t.SO_HIEU ,lt.TEN, t.loai_toa from TOA t ,LOAI_TOA lt where t.TAU='%s' and t.LOAI_TOA=lt.ID", this.jtfTau.getText());
                rs = ExcuteQuery.TimKiemTatCa(sql);
                ArrayList<ToaDTO> dsdt = new ArrayList<ToaDTO>();
                while (rs.next()) {
                    ToaDTO temp = new ToaDTO();
                    temp.SoHieu=rs.getString("So_Hieu");
       
                    dsdt.add(temp);
                }
                for (ToaDTO k : dsdt) {
                    f.addElement(k.SoHieu);
            
                }
                jcbToa.setModel(f);
            
            
            
            
        } catch (SQLException ex) {
            Logger.getLogger(BanVeGUI.class.getName()).log(Level.SEVERE, null, ex);
        }
        
            
    }//GEN-LAST:event_jcbChuyenActionPerformed
DefaultComboBoxModel<String> j = new DefaultComboBoxModel<String>();
DefaultComboBoxModel<String> j1 = new DefaultComboBoxModel<String>();
    private void jcbToaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jcbToaActionPerformed
        try {
            // TODO add your handling code here:
            String tentoa = jcbToa.getSelectedItem().toString();
            //
              String sql1 = String.format("select  t.SO_HIEU ,lt.TEN, t.loai_toa from TOA t ,LOAI_TOA lt where t.TAU='%s' and t.LOAI_TOA=lt.ID AND t.so_hieu ='%s'", this.jtfTau.getText(),tentoa);
                rs = ExcuteQuery.TimKiemTatCa(sql1);
                ArrayList<ToaDTO> dsdt1 = new ArrayList<ToaDTO>();
                while (rs.next()) {
                    ToaDTO temp = new ToaDTO();
                    temp.LoaiToa = rs.getInt("loai_toa");
                    dsdt1.add(temp);
                }
                for (ToaDTO k : dsdt1) {
                    if( k.LoaiToa == 1){
                        jtfLoaiGhe.setText("Ghế thường");
                    }
                    if( k.LoaiToa == 2){
                          jtfLoaiGhe.setText("Giường nằm");
                    }
                }
            //
                
           String loaighe = jtfLoaiGhe.getText();
           
            if(loaighe.equals("Ghế thường")){
            String sql = String.format("select g.*,tt.TEN from GHE g , TINH_TRANG_GHE tt where g.TOA='%s' and g.TINH_TRANG=tt.ID and tt.ID = 1", tentoa);
            rs = ExcuteQuery.TimKiemTatCa(sql);
            ArrayList<Ghe> dsdt = new ArrayList<Ghe>();
            while (rs.next()) {
                Ghe temp = new Ghe();
                temp.SoHieu=rs.getString("So_Hieu");
                dsdt.add(temp);
            }
            for (Ghe k : dsdt) {
                j.addElement(k.SoHieu);
            }
            jcbGheGiuong.setModel(j);
            
            }
             if(loaighe.equals("Giường nằm")){
                 String sql = String.format("select p.SO_HIEU,p.TOA ,g.SO_HIEU as SH_GIUONG,g.TANG,g.GIA,tt.TEN from PHONG p, GIUONG g ,TINH_TRANG_GHE tt where p.TOA='%s' and p.SO_HIEU=g.PHONG and g.TINH_TRANG=tt.ID", tentoa);
            rs = ExcuteQuery.TimKiemTatCa(sql);
            ArrayList<Ghe> dsdt = new ArrayList<Ghe>();
            while (rs.next()) {
                Ghe temp = new Ghe();
                temp.SoHieu=rs.getString("So_Hieu");
                dsdt.add(temp);
            }
            for (Ghe k : dsdt) {
                j1.addElement(k.SoHieu);
            }
            jcbGheGiuong.setModel(j1);
             }
            
     
        } catch (SQLException ex) {
            Logger.getLogger(BanVeGUI.class.getName()).log(Level.SEVERE, null, ex);
        }
    }//GEN-LAST:event_jcbToaActionPerformed

    private void jcbGheGiuongActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jcbGheGiuongActionPerformed
        try {
            // TODO add your handling code here:
            String tentoa = jcbToa.getSelectedItem().toString();
            String loaighe = jtfLoaiGhe.getText();
            if(loaighe.equals("Ghế thường")){
            
            String sql = String.format("select g.*,tt.TEN from GHE g , TINH_TRANG_GHE tt where g.TOA='%s' and g.TINH_TRANG=tt.ID ", tentoa);
            rs = ExcuteQuery.TimKiemTatCa(sql);
            Double giaghe;
           
            ArrayList<Ghe> dsdt = new ArrayList<Ghe>();
            while (rs.next()) {
                Ghe temp = new Ghe();
                temp.SoHieu=rs.getString("So_Hieu");
              
                temp.Gia = rs.getDouble("gia");
                temp.TinhTrang = rs.getInt("tinh_trang");
                dsdt.add(temp);
            }
            for (Ghe k : dsdt) {
                 if( jcbGheGiuong.getSelectedItem().equals( k.SoHieu) ){
                    giaghe = k.Gia;
                    this.jtfGiaGhe.setText(giaghe.toString());
                    if ( k.TinhTrang == 1){
                         this.jtfTinhTrang.setText("Vancant seat");
                    }
                    else{
                        this.jtfTinhTrang.setText("Booked");
                    }
                }
            }
            }
            if(loaighe.equals("Giường nằm")){
                  String sql = String.format("select p.SO_HIEU,p.TOA ,g.SO_HIEU  as SH_GIUONG,g.TANG,g.GIA,tt.TEN, g.TINH_TRANG from PHONG p, GIUONG g ,TINH_TRANG_GHE tt where p.TOA='%s' and p.SO_HIEU=g.PHONG and g.TINH_TRANG=tt.ID", tentoa);
            rs = ExcuteQuery.TimKiemTatCa(sql);
            Double giaghe;
           
            ArrayList<Ghe> dsdt = new ArrayList<Ghe>();
            while (rs.next()) {
                Ghe temp = new Ghe();
                temp.SoHieu=rs.getString("So_Hieu");
              
                temp.Gia = rs.getDouble("gia");
                temp.TinhTrang = rs.getInt("TINH_TRANG");
                dsdt.add(temp);
            }
            for (Ghe k : dsdt) {
                 if( jcbGheGiuong.getSelectedItem().equals( k.SoHieu) ){
                    giaghe = k.Gia;
                    this.jtfGiaGhe.setText(giaghe.toString());
                    if ( k.TinhTrang == 1){
                         this.jtfTinhTrang.setText("Vancant seat");
                    }
                    else{
                        this.jtfTinhTrang.setText("Booked");
                    }
                }
            }
            }
        } catch (SQLException ex) {
            Logger.getLogger(BanVeGUI.class.getName()).log(Level.SEVERE, null, ex);
        }
        
    }//GEN-LAST:event_jcbGheGiuongActionPerformed

    public  DefaultTableModel tableModel ;
    public void optionTable() 
{ 
        //Tạo model cho table 
       tableModel = new DefaultTableModel() { 
            @Override//Override lại phương thức isCellEditable 
            public boolean isCellEditable(int row, int column) { 
                return false;//Trả về false không cho edit. 
            } 
        }; 
        jtbBanVe.setModel(tableModel);//set Model cho table 
        /* Tạo mới Vector chứa Column Header */
        Vector column = new Vector();
        column.add("CHUYEN_TAU"); 
        column.add("TOA"); 
        column.add("GHE"); 
        column.add("GIA_VE"); 
        column.add("KHACH_HANG"); 
        column.add("DOI_TUONG");         
        column.add("NHAN_VIEN"); 
        column.add("NGAY_BAN"); 
        /* Set Column Header lên DefaultTableModel */
        tableModel.setColumnIdentifiers(column);
        
         Vector row = new Vector();
            row.add(jcbChuyen.getSelectedItem());
            row.add(jcbToa.getSelectedItem());
            row.add(jcbGheGiuong.getSelectedItem());
            row.add(jlbGiaVe.getText());
            row.add(jcbTenKH.getSelectedItem());
            row.add(jcbDoiTuong.getSelectedItem());
            row.add(jLabelTenNV.getText());
            Calendar cal = Calendar.getInstance();
            String NgayTao =String.valueOf(cal.get(Calendar.YEAR)) + "-" + String.valueOf(cal.get(Calendar.MONTH) + 1) + "-" +String.valueOf(cal.get(Calendar.DATE));
            row.add(NgayTao);
            tableModel.addRow(row);
     

}
   
    private void jbTim1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbTim1ActionPerformed
        // TODO add your handling code here:
           if ( jtfTinhTrang.getText()== "Booked"){
                JOptionPane.showMessageDialog(null, "Ghế đã được đặt","Thông Báo" , JOptionPane.INFORMATION_MESSAGE);
                return;
            }
              if ( jcbChuyen.getSelectedItem()==""){
           JOptionPane.showMessageDialog(null, "Bạn chưa chọn chuyến","Thông Báo" , JOptionPane.INFORMATION_MESSAGE);
           return;
           }
            if ( jcbToa.getSelectedItem()==""){
                JOptionPane.showMessageDialog(null, "Bạn chưa chọn toa","Thông Báo" , JOptionPane.INFORMATION_MESSAGE);
                return;
            }
           if ( jcbGheGiuong.getSelectedItem()==""){
                JOptionPane.showMessageDialog(null, "Bạn chưa chọn Ghế / Giường","Thông Báo" , JOptionPane.INFORMATION_MESSAGE);
                return;
            }
           if ( jcbDoiTuong.getSelectedItem()==""){
                JOptionPane.showMessageDialog(null, "Bạn chưa chọn đối tượng","Thông Báo" , JOptionPane.INFORMATION_MESSAGE);
                return;
            }
             if ( jcbTenKH.getSelectedItem()==""){
                JOptionPane.showMessageDialog(null, "Bạn chưa chọn Tên khách hàng mua vé","Thông Báo" , JOptionPane.INFORMATION_MESSAGE);
                return;
            }
             else {
                optionTable();
             }
        
    }//GEN-LAST:event_jbTim1ActionPerformed
public int GiaGhe ;
    private void jcbDoiTuongActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jcbDoiTuongActionPerformed
        try {
         // Đối Tượng
            int doituong=0;
            int giamgiadoituong =0;
            String sql9 = "Select n.ID, n.Ten, n.giam_gia from doi_tuong n";
            rs = ExcuteQuery.TimKiemTatCa(sql9);
            ArrayList<DoiTuongDTO> dsdt = new ArrayList<DoiTuongDTO>();
            while (rs.next()) {
                DoiTuongDTO temp = new DoiTuongDTO();
                temp.id = rs.getInt("ID");
                temp.Ten = rs.getString("Ten");
                temp.giamgia = rs.getInt("giam_gia");
                dsdt.add(temp);
            }
            for (DoiTuongDTO k : dsdt) {
                if( jcbDoiTuong.getSelectedItem().equals( k.Ten) ){
                    doituong = k.id;
                    giamgiadoituong = k.giamgia;
                }
            }
            
            
             double giaghe = Double.parseDouble(jtfGiaGhe.getText());
             Double PhanTramGiaGhe = giaghe / 100;

            int giamgianguoi = giamgiadoituong;
            giaghe = (int)(giaghe - (giamgianguoi * PhanTramGiaGhe));

            /// Đối tượng tăng giá
             int gadi =0;
            int gaden =0;
            
            String sql2 = "Select n.ID, n.Ten from Ga n";
            ResultSet rs = ExcuteQuery.TimKiemTatCa(sql2);
            ArrayList<GaDTO> dsga = new ArrayList<GaDTO>();
            while (rs.next()) {
                GaDTO temp = new GaDTO();
                temp.id = rs.getInt("ID");
                temp.tenga = rs.getString("Ten");
                dsga.add(temp);
            }
            for (GaDTO k : dsga) {
                if( jcbGaDen.getSelectedItem().equals( k.tenga) ){
                    gaden = k.id;
                }
                if( jcbGaDi.getSelectedItem().equals( k.tenga) ){
                    gadi = k.id;
                }
            }
             String tuyen = TuyenTauDAO.timTuyen(gadi, gaden);
            rs = TuyenTauDAO.timTuyenTauCanDi(tuyen, sdf.format(jDateNgayDi.getDate()).toString());
            ArrayList<ChuyenTauDTO> dsct = new ArrayList<ChuyenTauDTO>();
            int dttanggia = 0;
            
            while (rs.next()) {
               ChuyenTauDTO temp = new ChuyenTauDTO();
                temp.id= rs.getString("Id");
                if( jcbChuyen.getSelectedItem().equals(temp.id) ){
                    dttanggia = rs.getInt("TANG_GIA");
                }
            }
            
            int tanggiatau = dttanggia;
            giaghe = (int)(giaghe + (tanggiatau * PhanTramGiaGhe));
            GiaGhe = (int)giaghe;
            jlbGiaVe.setText(String.valueOf(giaghe));
            
            
            
        } catch (SQLException ex) {
            Logger.getLogger(BanVeGUI.class.getName()).log(Level.SEVERE, null, ex);
        }
        
    }//GEN-LAST:event_jcbDoiTuongActionPerformed

    private void jbTim2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbTim2ActionPerformed

        // Thêm hóa đơn
        Double TongTien = 0.0;
              
                HoaDonDTO HoaDon = new HoaDonDTO();
              
                HoaDon.id = jtfHoaDon.getText();
                Calendar cal = Calendar.getInstance();
                HoaDon.ngaytao = String.valueOf(cal.get(Calendar.YEAR)) + "-" + String.valueOf(cal.get(Calendar.MONTH) + 1) + "-" +String.valueOf(cal.get(Calendar.DATE));
                HoaDon.tongtien = TongTien;
                // 
             String sql5 = "select nd.id, nd.ho_ten from Nguoi_Dung nd where nd.loai_nguoi_dung = 1";
             rs = ExcuteQuery.TimKiemTatCa(sql5);
             
            ArrayList<NguoiDung> dskh = new ArrayList<NguoiDung>();
        try {
            while (rs.next()) {
                try {
                    NguoiDung temp = new NguoiDung();
                    temp.Id = rs.getInt("id");
                    temp.HoTen = rs.getString("ho_ten");
                    dskh.add(temp);
                    for (NguoiDung k : dskh) {
                        if(jcbTenKH.getSelectedItem().equals(k.HoTen)){
                            HoaDon.khachhang = k.Id;
                        }
                    }
                } catch (SQLException ex) {
                    Logger.getLogger(BanVeGUI.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
     
                
             HoaDonBUS.Them(HoaDon);
        
        // Thêm ghế
             if(jtfLoaiGhe.getText() =="Ghế thường"){
                 TinhTrangGheBUS.UpdateGhe(jcbGheGiuong.getSelectedItem().toString());
             }
              if(jtfLoaiGhe.getText() =="Giường nằm"){
                 TinhTrangGheBUS.UpdateGiuong(jcbGheGiuong.getSelectedItem().toString());
             }
            // jtbBanVe.getValueAt(WIDTH, WIDTH)
              
        
        // Thêm vé
              
             VeDTO Ve = new VeDTO();
                    Ve.TinhTrangVe = 1;
                    Ve.Ghe = jcbGheGiuong.getSelectedItem().toString();
                    Ve.GiaVe = GiaGhe;
                    TongTien = TongTien + Ve.GiaVe;
                    Ve.Chuyen = jcbChuyen.getSelectedItem().toString();
                    Ve.HoaDon = jtfHoaDon.getText();
                 
                 
                    Ve.NgayTao =String.valueOf(cal.get(Calendar.YEAR)) + "-" + String.valueOf(cal.get(Calendar.MONTH) + 1) + "-" +String.valueOf(cal.get(Calendar.DATE));
                
                    String sql2 = "Select n.ID, n.Ten from Ga n";
                    ResultSet rs = ExcuteQuery.TimKiemTatCa(sql2);
                    ArrayList<GaDTO> dsga = new ArrayList<GaDTO>();
                    while (rs.next()) {
                        GaDTO temp = new GaDTO();
                        temp.id = rs.getInt("ID");
                        temp.tenga = rs.getString("Ten");
                        dsga.add(temp);
                    }
                    for (GaDTO k : dsga) {
                        if( jcbGaDen.getSelectedItem().equals( k.tenga) ){
                           Ve.GaDen = k.id;
                        }
                        if( jcbGaDi.getSelectedItem().equals( k.tenga) ){
                             Ve.GaDi  = k.id;
                        }
                    }
                   // Đối Tượng
                String sql9 = "Select n.ID, n.Ten from doi_tuong n";
                rs = ExcuteQuery.TimKiemTatCa(sql9);
                ArrayList<DoiTuongDTO> dsdt = new ArrayList<DoiTuongDTO>();
                while (rs.next()) {
                    DoiTuongDTO temp = new DoiTuongDTO();
                    temp.id = rs.getInt("ID");
                    temp.Ten = rs.getString("Ten");
                    dsdt.add(temp);
                }
                for (DoiTuongDTO k : dsdt) {
                    if( jcbDoiTuong.getSelectedItem().equals( k.Ten) ){
                    Ve.DoiTuong = k.id;
                }
                }
                    
                    VeBUS.Them(Ve);
                    
                    JOptionPane.showMessageDialog(null, "Thanh Toán Thành Công","Thông Báo" , JOptionPane.INFORMATION_MESSAGE);
   } catch (SQLException ex) {
            Logger.getLogger(BanVeGUI.class.getName()).log(Level.SEVERE, null, ex);
        }

    }//GEN-LAST:event_jbTim2ActionPerformed


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private com.toedter.calendar.JDateChooser jDateNgayDi;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel14;
    private javax.swing.JLabel jLabel15;
    private javax.swing.JLabel jLabel16;
    private javax.swing.JLabel jLabel17;
    private javax.swing.JLabel jLabel18;
    private javax.swing.JLabel jLabel19;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel20;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JLabel jLabelLoaiNV;
    private javax.swing.JLabel jLabelTenNV;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JPanel jPanel5;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JButton jbTim;
    private javax.swing.JButton jbTim1;
    private javax.swing.JButton jbTim2;
    private javax.swing.JComboBox jcbChuyen;
    private javax.swing.JComboBox jcbDoiTuong;
    private javax.swing.JComboBox jcbGaDen;
    private javax.swing.JComboBox jcbGaDi;
    private javax.swing.JComboBox jcbGheGiuong;
    private javax.swing.JComboBox jcbTenKH;
    private javax.swing.JComboBox jcbToa;
    private javax.swing.JLabel jlbGiaVe;
    private javax.swing.JTable jtbBanVe;
    private javax.swing.JTextField jtfGiaGhe;
    private javax.swing.JTextField jtfGioiTinh;
    private javax.swing.JTextField jtfHoaDon;
    private javax.swing.JTextField jtfLoaiGhe;
    private javax.swing.JTextField jtfSDT;
    private javax.swing.JTextField jtfSoCMNDKH;
    private javax.swing.JTextField jtfTau;
    private javax.swing.JTextField jtfTinhTrang;
    // End of variables declaration//GEN-END:variables
}
